package com.wl.mr.join;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

public class DeliveMapper extends Mapper<LongWritable, Text,Text,DeliveBean> {
    String name;
    DeliveBean deliveBean = new DeliveBean();
    Text k = new Text();
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        name = inputSplit.getPath().getName();
    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split("\t");
        if(name.equalsIgnoreCase("deliver_info")){
            deliveBean.setUserId(fields[0]);
            deliveBean.setPositionId(fields[1]);
            deliveBean.setDate(fields[2]);
            deliveBean.setPositionName("");
            deliveBean.setFlag("deliver");
            k.set(fields[1]);
        }else {
            deliveBean.setUserId("");
            deliveBean.setPositionId(fields[0]);
            deliveBean.setDate("");
            deliveBean.setPositionName(fields[1]);
            deliveBean.setFlag("position");
            k.set(fields[0]);
        }
        context.write(k,deliveBean);
    }
}
